package com.seaboxdata.jt809.kafka.serializer;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.seaboxdata.jt809.packet.JT809Packet0x1202;
import org.apache.kafka.common.serialization.Deserializer;

import java.util.Map;

/**
 * @ClassName JT809Packet0x1202Serializer
 * @Description JT809Packet0x1202反序列化类
 * @Author DFJX
 * @Company 北京东方金信科技有限公司
 * @Date 2020/7/21 9:00
 * Version 1.0
 **/
public class JT809Packet0x1202Deserializer implements Deserializer<JT809Packet0x1202> {
    @Override
    public void configure(Map<String, ?> map, boolean b) {

    }

    @Override
    public JT809Packet0x1202 deserialize(String s, byte[] bytes) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
        mapper.registerModule(new JavaTimeModule());
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        JT809Packet0x1202 packet0x1202 = null;
        try {
            String str=new String(bytes);
            str=str.replace("\\u0000","");
            //System.out.println(str);
            packet0x1202 = mapper.readValue(str.getBytes(),JT809Packet0x1202.class);
           // System.out.println("读取信息："+packet0x1202);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return packet0x1202;
    }

    @Override
    public void close() {

    }
}
